package com.chixing.controller;

import com.chixing.pojo.Customer;
import com.chixing.pojo.Point;
import com.chixing.service.PointService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;


@Controller
public class PointController {
    @Autowired
    private PointService pointService;

    @PutMapping("order")
    @ResponseBody
    public ServerResponse update(Point point){
        ServerResponse serverResponse1 = pointService.update(point);
        return serverResponse1;
    }
    @PutMapping("coupon")
    @ResponseBody
    public ServerResponse update1(Point point){
        ServerResponse serverResponse2 = pointService.update(point);
        return serverResponse2;
    }
    @GetMapping("vip/point/{vipId}")
    public  ModelAndView getByVipId(@PathVariable("vipId") Integer vipId){
        ModelAndView mav = new ModelAndView();
        ServerResponse pointServer = pointService.getVipId(vipId);
        mav.addObject("pointServer",pointServer);
        mav.setViewName("coupon/coupon");
        return mav;
    }
    @GetMapping("evaluate/point/{cusId}")
    @ResponseBody
    public ServerResponse getByCusId(HttpSession httpSession){
        Customer customer = (Customer) httpSession.getAttribute("loginCustomer");
        Integer cusId = customer.getCusId();
        return pointService.getByCusId(cusId);
    }
}
